package com.qf.service.impl;

import com.qf.pojo.DtsAdmin;
import com.qf.pojo.DtsBrand;
import com.qf.service.DtsAdminDataAuthService;
import com.qf.service.DtsBrandService;
import com.qf.service.DtsRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * @author ZhangYuJie
 * projectName:shop_manage
 * time:2022/5/17 21:16
 * description:
 */
@Service
public class DtsAdminDataAuthServiceImpl implements DtsAdminDataAuthService {

    @Autowired
    private DtsRoleService roleService;

    @Autowired
    private DtsBrandService brandService;

    @Override
    public boolean isBrandManager(DtsAdmin currentUser) {
        Integer[] roleIds = null;
        if (currentUser != null) {
            roleIds = currentUser.getRoleIds();
            Set<String> roles = roleService.queryByIds(roleIds);
            //仅仅只是品牌管理员且不属于超级管理员
            if (roles.contains("品牌制造商") && !roles.contains("超级管理员")) {
                return true;
            }
        }
        return false;
    }

    @Override
    public List<Integer> getBrandIds(DtsAdmin currentUser) {
        List<Integer> brandIds = null;
        List<DtsBrand> brands = brandService.getAdminBrands(currentUser.getId());
        if (brands != null && brands.size() > 0) {
            brandIds = new ArrayList<Integer>();
            for (DtsBrand brand:brands) {
                brandIds.add(brand.getId());
            }
        }
        return brandIds;
    }
}
